package com.pengtu.gsj.controller.yh;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.yh.MainBulletin;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.yh.MainBulletinService;

@Controller
@RequestMapping("mainBulletin")
public class MainBulletinController extends DefaultBaseController{

	@Autowired
	private MainBulletinService mainBulletinService;
	
	/**
	 * 
	 * load:
	 * 适用:每个请求执行前都会执行该方法，绑定特定对象供更新和删除使用
	 * @param id  对象id
	 * @return 业务数据对象
	 * @exception 
	 * @since  1.0.0
	 */
	@ModelAttribute
	public MainBulletin load(String id) {
		MainBulletin mainBulletin;
		if (StringUtils.isNotEmpty(id)) {
			mainBulletin = mainBulletinService.getMainBulletinById(id);
		}else {
			mainBulletin = new MainBulletin();
		}
		return mainBulletin;
	}
	
	/**
	 * 
	 * showLisfInfo:
	 * 适用:跳转到显示养护工作记录列表
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showLisfInfo() {
		return "yh/mainBulletin_list";
	}
	
	/**
	 * 
	 * getMainBulletinList:
	 * 适用:jqgrid请求记录数据
	 * @param page
	 * @param request
	 * @return 返回记录及页面相关数据信息
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="list", produces = "application/json; charset=utf-8")
	@ResponseBody
	public Page<MainBulletin> getMainBulletinList(Page<MainBulletin> page, HttpServletRequest request){
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("bullentinYear,createDate");
			page.setOrder("asc,desc");
		}
		page = mainBulletinService.findMainBulletin(page, queryFilter);
		return page;
	}
	
	/**
	 * 
	 * saveMainBulletin:
	 * 适用:保存及更新记录数据
	 * @param mainBulletin  通过id绑定的特定对象
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveMainBulletin(@ModelAttribute MainBulletin mainBulletin) {
		mainBulletinService.saveMainBulletin(mainBulletin);
		return true;
	}
	
	/**
	 * 
	 * showMainBulletin:
	 * 适用:ajax请求获得特定对象返回到页面显示
	 * @param mainBulletin
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="show")
	@ResponseBody                                                     
	public MainBulletin showMainBulletin(@ModelAttribute MainBulletin mainBulletin){
		return mainBulletin;
	}
	
	/**
	 * 
	 * deleteMainBulletin:
	 * 适用:ajax删除指定对象
	 * @param mainBulletin  通过id获得的指定对象
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean deleteMainBulletin(@ModelAttribute MainBulletin mainBulletin){
		 mainBulletinService.deleteMainBullentin(mainBulletin);
		return true;
	}

	
}
